Imports capaNegocios.Gestor
Imports CrystalDecisions.CrystalReports.EPFPageObjectFactory.PageObjectFactory
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Shared.SubreportContext
Partial Class Pagina
    Inherits System.Web.UI.Page
    Private objG As capaNegocios.Gestor = objg.instanciar()
    Private datos, dato As ArrayList
    Private nom As String
    Private es As Data.DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        datos = objG.cargarGruposActivosWeb(Session.Item("carnet"))
        If Not Me.IsPostBack Then
            Dim i As Integer
            For i = 0 To datos.Count - 1
                dato = datos.Item(i)
                Me.comboGrupos.Items.Add(dato.Item(2))
            Next
        End If
        Dim index As Integer = Me.comboGrupos.SelectedIndex
        dato = datos.Item(index)
        Session("pidg") = dato.Item(1)
        Session("pide") = dato.Item(0)
        dato = objG.mostrarPromedioEstudiante(Session("pidg"), Session("pide"))
        Dim a, b, c, d, r, f As ArrayList
        a = dato.Item(0)
        b = dato.Item(1)
        c = dato.Item(2)
        d = dato.Item(3)
        r = dato.Item(4)
        f = dato.Item(5)
        Me.general1.Text = a.Item(0) & " %  / " & a.Item(1) & " % "
        Me.general2.Text = b.Item(0) & " %  / " & b.Item(1) & " % "
        Me.general3.Text = c.Item(0) & " %  / " & c.Item(1) & " % "
        Me.individual1.Text = d.Item(0) & " %  / " & d.Item(1) & " % "
        Me.individual2.Text = r.Item(0) & " %  / " & r.Item(1) & " % "
        Me.individual3.Text = f.Item(0) & " %  / " & f.Item(1) & " % "
        es = objG.darEstudiante(Session("pidg"), Session("pide"))
        nom = CType(es.Rows.Item(0).Item(0) + " " + es.Rows.Item(0).Item(1), String)
        Me.nombre.Text = nom
    End Sub
    Protected Sub ObjectDataSource1_ObjectCreating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceEventArgs) Handles ObjectDataSource1.ObjectCreating
        e.ObjectInstance = objG
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Dim da, dc As New Data.DataTable
        da = objG.mostrarDesgloseEstudiante(Session("pidg"), Session("pide"))
        dc = objG.obtenerElGrupoActivo(Session("pidg"))
        Me.informe.ReportDocument.SetDataSource(da)
        Me.informe.ReportDocument.OpenSubreport("InfoEstudiante").SetDataSource(es)
        Me.informe.ReportDocument.OpenSubreport("InfoGrupo").SetDataSource(dc)
        Dim rptStream As New System.IO.MemoryStream
        rptStream = CType(Me.informe.ReportDocument.ExportToStream(ExportFormatType.PortableDocFormat), System.IO.MemoryStream)
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = nom + ".pdf"
        Response.AddHeader("Content-Disposition", "attachment;filename=" + nom + ".pdf")
        Response.BinaryWrite(rptStream.ToArray())
        Response.End()
    End Sub
End Class
